package com.game.object;

import android.graphics.Point;
import android.graphics.Rect;

import com.game.framwork.gamesupport.GameSprite;
import com.game.framwork.itf.Graphics;
import com.game.framwork.itf.Pixmap;
import com.game.tiledmap.TiledMap;

public abstract class JObject {
	public TiledMap tiledMap;
	protected Pixmap objectImage;
	public Point position;
	public Point prevPosition;
	public int objectWidth;
	public int objectHeight;

	public int frameWidth;
	public int frameHeight;

	public boolean isVisible;
	public boolean isDeath;
	public boolean isDying;
	public boolean canCollision;
	public boolean canBeDestroy;
	public boolean isDestroy;

	protected int offsetBottom;
	protected int offsetRight;
	protected Rect rectBoundBox;
	public GameSprite sprite;
	public int posOnMap;

	protected JObject() {
		tiledMap = new TiledMap();
		position = new Point();
		prevPosition = new Point();
		posOnMap =  0;
		objectWidth = 0;
		objectHeight = 0;
		frameWidth = 0;
		frameHeight = 0;
		objectImage = null;
		rectBoundBox = new Rect();
		sprite = null;
		isVisible = true;
	}
	
	public void attachTiledMap(TiledMap tiledMap) {
		this.tiledMap = tiledMap;
	}
	
	// / <summary>
	// / Set Size of this object
	// / </summary>
	protected void setSize(int objWidth, int objHeight) {
		objectWidth = frameWidth = objWidth;
		objectHeight = frameHeight = objHeight;
	}

	// / <summary>
	// / Set instance of texture image for this object
	// / </summary>
	protected void setImage(Pixmap image, int imageWidth, int imageHeight) {
		sprite = new GameSprite(image);
		objectImage = image;
		setSize(imageWidth, imageHeight);
	}

	// / <summary>
	// / Get a sprite instance of this object
	// / </summary>
	protected GameSprite getSprite() {
		return sprite;
	}

	// / <summary>
	// / Create new bounding box
	// / </summary>
	public void createBoundBox(int offsetRight, int offsetBot, int offsetWidth,
			int offsetHeight) {
		offsetBottom = offsetBot;
		this.offsetRight = offsetRight;
		objectWidth = offsetWidth;
		objectHeight = offsetHeight;
	}

	// / <summary>
	// / Move our object by a given amount
	// / </summary>
	protected void Move(int dx, int dy) {
		prevPosition = position;
		/*if (prevPosition.x + dx >= 0
				&& prevPosition.x + dx >= map.mapWidth * map.cellSize
				&& prevPosition.x + dy >= 0
				&& prevPosition.x + dy >= map.mapHeight * map.cellSize) {
			
		}*/
		position = new Point(prevPosition.x + dx, prevPosition.y + dy);
	}

	public void paintInternal(Graphics g) {
	
	}

	public void updateInternal(float deltaTime) {

	}

	// / <summary>
	// / Get the bounding box of this object
	// / </summary>
	public Rect getBoundBox() {
		rectBoundBox = new Rect(position.x - objectWidth / 2 + offsetRight
				+ tiledMap.getCamera().getCameraX(), position.y - objectHeight / 2 + offsetBottom
				+ tiledMap.getCamera().getCameraY(), position.x + objectWidth / 2 + offsetRight
				+ tiledMap.getCamera().getCameraX(), position.y + objectHeight / 2 + offsetBottom
				+ tiledMap.getCamera().getCameraY());
		return rectBoundBox;
	}

	// / <summary>
	// / Collision checking with other object
	// / </summary>
	public boolean Collision(JObject pObj) {
		if (this.getBoundBox().intersect(pObj.getBoundBox()))
			return true;
		return false;
	}

	public void setPossition(Point pos) {
		position = pos;
	}
	
	public Point getPossition() {
		return position;
	}

}
